package com.weng.bigdata.core.jdbc.enums;

import java.sql.SQLType;
import java.sql.Types;

/**
 *  hive 字段类型枚举 基于SQLType 枚举
 * @author wengzhonghui
 */
public enum HiveJdbcTypesEnum implements SQLType {

    /**
     * Identifies the generic SQL type {@code TINYINT}.
     */
    TINYINT(Types.TINYINT,"TINYINT"),
    /**
     * Identifies the generic SQL type {@code SMALLINT}.
     */
    SMALLINT(Types.SMALLINT,"SMALLINT"),
    /**
     * Identifies the generic SQL type {@code INTEGER}.
     */
    INTEGER(Types.INTEGER,"INTEGER"),
    /**
     * Identifies the generic SQL type {@code INTEGER}.
     */
    INT(Types.INTEGER,"INTEGER"),
    /**
     * Identifies the generic SQL type {@code BIGINT}.
     */
    BIGINT(Types.BIGINT,"BIGINT"),
    /**
     * Identifies the generic SQL type {@code FLOAT}.
     */
    FLOAT(Types.FLOAT,"DECIMAL"),
    /**
     * Identifies the generic SQL type {@code DOUBLE}.
     */
    DOUBLE(Types.DOUBLE,"DECIMAL"),
    /**
     * Identifies the generic SQL type {@code NUMERIC}.
     */
    NUMERIC(Types.NUMERIC,"DECIMAL"),
    /**
     * Identifies the generic SQL type {@code DECIMAL}.
     */
    DECIMAL(Types.DECIMAL,"DECIMAL"),

    /**
     * Identifies the generic SQL type {@code DECIMAL}.
     */
    REAL(Types.REAL,"INTEGER"),

    /**
     * Identifies the generic SQL type {@code CHAR}.
     */
    CHAR(Types.CHAR,"STRING"),

    /**
     * Identifies the generic SQL type {@code CHAR}.
     */
    LONGVARCHAR(Types.LONGVARCHAR,"STRING"),

    /**
     * Identifies the generic SQL type {@code VARCHAR}.
     */
    STRING(Types.VARCHAR,"STRING"),


    /**
     * Identifies the generic SQL type {@code VARCHAR}.
     */
    BLOB(Types.BLOB,"STRING"),

    /**
     * Identifies the generic SQL type {@code VARCHAR}.
     */
    CLOB(Types.CLOB,"STRING"),

    /**
     * Identifies the generic SQL type {@code VARCHAR}.
     */
    BOOLEAN(Types.BOOLEAN,"BOOLEAN"),

    /**
     * Identifies the generic SQL type {@code DATE}.
     */
    DATE(Types.DATE,"String"),
    /**
     * Identifies the generic SQL type {@code TIME}.
     */
    TIME(Types.TIME,"String "),
    /**
     * Identifies the generic SQL type {@code TIMESTAMP}.
     */
    TIMESTAMP(Types.TIMESTAMP,"String"),
    /**
     * Identifies the generic SQL type {@code BINARY}.
     */
    BINARY(Types.BINARY,"BINARY"),

    /**
     * Identifies the generic SQL type {@code STRUCT}.
     */
    STRUCT(Types.STRUCT,"STRUCT"),
    /**
     * Identifies the generic SQL type {@code ARRAY}.
     */
    ARRAYS(Types.ARRAY,"ARRAYS");



    /**
     * The Integer value for the JDBCType.  It maps to a value in
     * {@code Types.java}
     */
    private Integer type;

    private String value;

    /**
     * Constructor to specify the data type value from {@code Types) for
     * this data type.
     * @param type The value from {@code Types) for this data type
     */
    HiveJdbcTypesEnum(final Integer type, String value) {
        this.value = value;
        this.type = type;
    }

    /**
     *{@inheritDoc }
     * @return The name of this {@code SQLType}.
     */
    public String getName() {
        return name();
    }
    /**
     * Returns the name of the vendor that supports this data type.
     * @return  The name of the vendor for this data type which is
     * {@literal java.sql} for JDBCType.
     */
    public String getVendor() {
        return "java.sql";
    }

    /**
     * Returns the vendor specific type number for the data type.
     * @return  An Integer representing the data type. For {@code JDBCType},
     * the value will be the same value as in {@code Types} for the data type.
     */
    public Integer getVendorTypeNumber() {
        return type;
    }
    /**
     * Returns the {@code JDBCType} that corresponds to the specified
     * {@code Types} value
     * @param type {@code Types} value
     * @return The {@code JDBCType} constant
     * @throws IllegalArgumentException if this enum type has no constant with
     * the specified {@code Types} value
     * @see Types
     */
    public static HiveJdbcTypesEnum valueOf(int type) {
        for( HiveJdbcTypesEnum sqlType : HiveJdbcTypesEnum.class.getEnumConstants()) {
            if(type == sqlType.type){
								return sqlType;
						}
        }
        throw new IllegalArgumentException("Type:" + type + " is not a valid "
                + "Types.java value.");
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
